﻿Namespace Forms.Edit

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class frmDiplomaRequirementDetails
    Inherits org.codegen.win.controls.frmBaseEdit

#Region "Designer"
    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    Friend WithEvents UcDiplomaRequirement As UcDiplomaRequirementDetails

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
            Me.UcDiplomaRequirement = New IIC.ucDiplomaRequirementDetails()
            Me.SuspendLayout()
            '
            'UcDiplomaRequirement
            '
            Me.UcDiplomaRequirement.AutoValidate = System.Windows.Forms.AutoValidate.EnableAllowFocusChange
            Me.UcDiplomaRequirement.Dock = System.Windows.Forms.DockStyle.Fill
            Me.UcDiplomaRequirement.Location = New System.Drawing.Point(0, 30)
            Me.UcDiplomaRequirement.ModelObject = Nothing
            Me.UcDiplomaRequirement.Name = "UcDiplomaRequirement"
            Me.UcDiplomaRequirement.Size = New System.Drawing.Size(573, 96)
            Me.UcDiplomaRequirement.TabIndex = 0
            '
            'frmDiplomaRequirementDetails
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(573, 148)
            Me.Controls.Add(Me.UcDiplomaRequirement)
            Me.Name = "frmDiplomaRequirementDetails"
            Me.ShowAdd = True
            Me.ShowDelete = True
            Me.ShowNavigationButtons = True
            Me.Text = "Diploma Requirement"
            Me.Controls.SetChildIndex(Me.UcDiplomaRequirement, 0)
            Me.ResumeLayout(False)
            Me.PerformLayout()

        End Sub


#End Region

#Region "Standard Code"

        Public Overrides Sub DeleteData()

            Dim mapper As DiplomaRequirementDBMapper = New DiplomaRequirementDBMapper()
            mapper.deleteByKey(Me.IdValue)

            'after delete, close the form
            'Note: do not set the dialog result here.  It is handled by the frmBaseEdit, ie do not call Me.DialogResult = Windows.Forms.DialogResult.None

        End Sub

        Public Overrides Sub LoadData()

            Me.UcDiplomaRequirement.ModelObject = New DiplomaRequirementDBMapper().findByKey(Me.IdValue)
            Me.UcDiplomaRequirement.loadData()
            Me.setRecordLoadedStatus(Me.IdValue)

        End Sub


        Public Overrides Function SaveData() As enumSaveDataResult

            If Me.ValidateChildren() Then
                Me.UcDiplomaRequirement.loadToObject()

                'here we modify the default save behavieor and save the 
                'Diploma and not the DiplomaRequirement.
                'There is logic in DiplomaType save to handle 
                'duplicate and active/not active DiplomaRequirements
                Dim diplomaTypeDBMapper As New DiplomaTypeDBMapper
                Dim diplomaRequirement As DiplomaRequirement = CType(Me.UcDiplomaRequirement.ModelObject, BusObjects.DiplomaRequirement)
                Dim dt As DiplomaType = diplomaTypeDBMapper.findByKey(diplomaRequirement.DiplomaTypeId.GetValueOrDefault)
                dt.AddDiplomaRequirement(diplomaRequirement)
                diplomaTypeDBMapper.save(dt)

                Return enumSaveDataResult.SAVE_SUCESS_AND_CLOSE
            Else
                Return enumSaveDataResult.SAVE_FAIL
            End If

        End Function

        Public Overrides Function dataChanged() As Boolean

            Return Me.UcDiplomaRequirement.hasChanges

        End Function

#End Region

		  Private Sub FormLoad(ByVal sender As Object, _
                                               ByVal e As System.EventArgs) Handles Me.Load

            AddHandler Me.UcDiplomaRequirement.DiplomaTypeId.SelectedValueChanged, _
                   AddressOf diplomaIdSelectionChanged

            If Me.NewRecord Then
                'call periodIdSelectionChanged to setup period, lesson drop downs
                Call diplomaIdSelectionChanged(Nothing, Nothing)
            End If
            Call Me.UcDiplomaRequirement.resetLastLoadedValues()
        End Sub

        Private Sub diplomaIdSelectionChanged(ByVal sender As Object, ByVal e As EventArgs)

            'after selection of PeriodId changed, limit the lessons shown 
            'to the ones that do not already exist in CLass table for 
            'the selected period
            If Me.UcDiplomaRequirement.DiplomaTypeId.SelectedValue Is Nothing Then
                Me.UcDiplomaRequirement.DiplomaTypeId.SelectedItem = Nothing
                Me.UcDiplomaRequirement.DiplomaTypeId.Enabled = False

            Else
                Me.UcDiplomaRequirement.CertificationTypeId.Enabled = True
                Dim newDiplomaId As Integer = CInt(Me.UcDiplomaRequirement.DiplomaTypeId.SelectedValue)
                Dim DiplomaSuperTypeId As Integer = DiplomaTypeDataUtils.findByKey(newDiplomaId).DiplomaSuperTypeId.GetValueOrDefault
                'load Certificates that are not already in a class for this period
                'Ticket #62: When adding a new CertificateRequirement to a diploma, the DiplomaSuperType must be the same
                Dim lsql As String = "CertificationTypeId not in " & _
                    "(select CertificationTypeid from DiplomaRequirement where IsActive=1 and DiplomaTypeId={0}) " & _
                    " and DiplomaSuperTypeId = {1}"
                Dim lsns As List(Of CertificationType) = CertificationTypeDataUtils.findList(lsql, newDiplomaId, DiplomaSuperTypeId)
                Me.UcDiplomaRequirement.setCertsDatasource(lsns)

            End If

        End Sub

End Class

End Namespace

